<template>
  <div class="article-box">
    <!-- 导航栏 -->
    <van-nav-bar fixed placeholder title="文章详情" left-arrow @click-left="$router.back()"/>
    <!-- 标题栏 -->
    <h1 class="title">{{ detail.title }}</h1>
    <!-- 作者信息 -->
    <div class="aut-box">
      <div class="left-box">
        <van-image round fit="cover" :src="detail.aut_photo" />
        <div>
          <div class="name">{{ detail.aut_name }}</div>
          <div class="time">{{ $relvTime(detail.pubdate) }}</div>
        </div>
      </div>

      <div class="right-box">
        <van-button icon="plus" type="info" size="small" round>关注</van-button>
      </div>
    </div>
    <!-- 文章内容 -->
    <div class="content" v-html="detail.content"></div>

    <!-- 评论区域 -->
    <my-comment />
  </div>
</template>

<script>
// 导入接口
import { detailAPI } from '@/api/article'
import MyComment from './MyComment.vue'
export default {
  name: 'MyArticle',
  components: {
    MyComment
  },
  destroyed () {
    console.log('article被销毁了')
  },
  data () {
    return {
      detail: {}
    }
  },
  async created () {
    const res = await detailAPI(this.$route.params.id)
    this.detail = res.data
  }
}
</script>

<style lang="less" scoped>
.article-box {
  padding: 0 15px;

  .title {
    padding: 15px 0;
    font-size: 18px;
  }

  .aut-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    .left-box {
      display: flex;
      align-items: center;

      .van-image {
        width: 80px;
        height: 80px;
        margin-right: 10px;
      }

      .time {
        color: gray;
        font-size: 12px;
        margin-top: 10px;
      }
    }
  }

  .content {
    ::v-deep {

      img {
        width: 100%;
      }
      p {
        width: 100%;
        word-break: break-all;
      }
      code {
        background-color: #000;
        color: gray;
        width: 100%;
        display: inline-block;
        overflow: auto;
      }
    }
  }
}
</style>
